package com.akkainaction.cluster.wordcount.router.spring;

import akka.actor.UntypedActor;
import com.akkainaction.cluster.wordcount.router.spring.service.CountingService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component("countingActor")
@Scope("prototype")
public class CountingActor extends UntypedActor {
 
	public static class Count {
	}
 
	public static class Get {
	}
 
	@Resource
	private CountingService countingService;
 
	private int count = 0;
 
	@Override
	public void onReceive(Object message) throws Exception {
		if (message instanceof Count) {
			count = countingService.increment(count);
		} else if (message instanceof Get) {
			getSender().tell(count, getSelf());
		} else {
			unhandled(message);
		}
	}
}